import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by kpradhan on 3/6/14.
 */
public class BoardFormatter {
    private List<String> unformatted = new ArrayList<String>(9);
    private String formatted;

    public BoardFormatter() {
        for (int i = 0; i < 9; i++) {
            unformatted.add(" ");
        }
    }

    public String blankBoard() {
        formatted =     " | | \n" +
                        "-----\n" +
                        " | | \n" +
                        "-----\n" +
                        " | | \n";

        return formatted;
    }

    public String format(String selection, String letter){
        Integer space = Integer.parseInt(selection);
        StringBuilder sb = new StringBuilder();

        if(unformatted.get(space)==" ") {
            unformatted.set(space, letter);
        } else {
            return "false";
        }

        for (int i = 0; i < 3; i++) {
            sb.append(unformatted.get(i));
            if(i<2) {
                sb.append("|");
            }
        }

        sb.append("\n-----\n");

        for (int i = 3; i < 6; i++) {
            sb.append(unformatted.get(i));
            if(i<5) {
                sb.append("|");
            }
        }
        sb.append("\n-----\n");

        for (int i = 6; i < 9; i++) {
            sb.append(unformatted.get(i));
            if(i<8) {
                sb.append("|");
            }
        }

        sb.append("\n");

        formatted = sb.toString();

        return formatted;
    }
}
